<?php
/* 
* @Author: LDF QQ 47121862
* @Date:   2014-05-27 14:09:39
* @Last Modified by:   LDF QQ 47121862
* @Last Modified time: 2014-06-05 12:21:42
*/
class GoodsTag{
	public $tag=array(
		'channel'=>array('block'=>1,'level'=>3),
		'goods'=>array('block'=>1,'level'=>3),
	);
	//栏目标签
	public function _channel($attr,$content){
		$cid = $attr['cid'];
		$php=<<<str
		<?php
			\$re = M('category')->where(array('cid'=>$cid))->all();
			foreach (\$re as \$field):
			\$field['url']=U('category',array('cid'=>$cid));
		?>
str;
		$php.=$content;
		$php.='<?php endforeach; ?>';
		return $php;
	}
	//商品标签
	public function _goods($attr,$content){
		$cid = $attr['cid'];
		$row = $attr['row'];
		$order = isset($attr['order'])?$attr['order']:'DESC';
		$php =<<<str
		<?php
			\$cid = explode(',',str_replace(' ','',"$cid"));
			\$re = M('goods')->where(array('cid'=>\$cid))->limit($row)->order('gid '.$order)->all();
			\$i=1;
			foreach (\$re as \$field):
			\$field['url']=U('content',array('cid'=>\$field['cid']));
			\$field['i']=\$i;
			\$i++;
		?>
str;
		$php.=$content;
		$php.='<?php endforeach ;?>';
		return $php;
	}
	//品牌
	public function _brand($attr,$content){
		$cid = $attr['cid'];
		$row = $attr['row'];
		$php=<<<str
		<?php
			\$re = M('brand')->where(array('cid'=>$cid))->limit($row)->all();
			foreach (\$re as \$field):
			\$field['url']=U('category',array('cid'=>$cid));
		?>
str;
		$php.=$content;
		$php.='<?php endforeach; ?>';
		return $php;
	}
}
